package com.selfdriving.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.selfdriving.BaseApplication;
import com.selfdriving.R;
import com.selfdriving.bean.Entity;
import com.selfdriving.bean.MyArticle;

public class PictureAlbumAdapter extends BaseAdapter
{
	private Context context;

	private List<Entity> features;

	private HolderView holderView;
	BaseApplication application;
	public DisplayImageOptions options;

	public PictureAlbumAdapter(BaseApplication application, Context context,
			List<Entity> features)
	{
		this.context = context;
		this.features = features;
		this.application = application;
		options = new DisplayImageOptions.Builder()
				.showImageOnLoading(R.drawable.default_loading)
				.showImageForEmptyUri(R.drawable.default_loading)
				.showImageOnFail(R.drawable.default_loading)
				.displayer(new RoundedBitmapDisplayer(10)).cacheInMemory(true)
				.cacheOnDisc(true).build();
	}

	@Override
	public int getCount()
	{
		return features.size();
	}

	@Override
	public Object getItem(int poistion)
	{
		return features.get(poistion);
	}

	@Override
	public long getItemId(int poistion)
	{
		return poistion;
	}

	@Override
	public View getView(int poistion, View view, ViewGroup arg2)
	{
		if (view == null)
		{
			holderView = new HolderView();
			view = ((LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
					.inflate(R.layout.picture_album_itme, null);
			view.setTag(holderView);
		} else
		{
			holderView = (HolderView) view.getTag();
		}
		holderView.bigImg = (ImageView) view.findViewById(R.id.ivBigImg);
		holderView.icon = (ImageView) view.findViewById(R.id.ivIcon);
		application.imageLoader.displayImage(
				"http://t10.baidu.com/it/u=2144300820,3407630733&fm=56",
				holderView.icon, options);
		application.imageLoader
				.displayImage(
						"http://d.hiphotos.baidu.com/image/w%3D2048/sign=4038c14ea38b87d65042ac1f33302938/6c224f4a20a44623fad3d61d9a22720e0cf3d7b0.jpg",
						holderView.bigImg, application.options);
		return view;
	}

	private class HolderView
	{
		private ImageView bigImg;

		private ImageView icon;

		private TextView name;

		private TextView num;
	}

}
